package com.atxiaodei.kabudashejimoshi.单例模式.懒汉式;

/**
 * @ClassName LazyDoubleCheckSingleton
 * @Deacription 为了解决单例模式在多线程的环境下，创建出来不同的实例，还有在synchronized，Cpu分配压力，造成线程出现阻塞的情况，
 * 我们选择使用双重检查锁的单例模式
 * @Author 卡布达
 * @Date 2021/10/12 12:49
 * @Version 1.0
 **/
public class LazyDoubleCheckSingleton {

    private volatile static LazyDoubleCheckSingleton lazyDoubleCheckSingleton=null;

    private LazyDoubleCheckSingleton(){}

    public static LazyDoubleCheckSingleton getInstance(){

        if(lazyDoubleCheckSingleton == null){// 双重检查锁

            synchronized(LazyDoubleCheckSingleton.class){

                if (lazyDoubleCheckSingleton ==null){

                    lazyDoubleCheckSingleton=new LazyDoubleCheckSingleton();

                }
            }
        }
        return lazyDoubleCheckSingleton;
    }
}
